<!DOCTYPE html>
<html lang="zh_CN">
<head>
  <meta charset="UTF-8">
  <title>子账户管理</title>
  <link href="/mix/bootstrap.min.css" rel="stylesheet">
  <link href="/mix/bootstrap-theme.min.css" rel="stylesheet">
  <link href="/mix/font-awesome.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/layui/css/layui.css">
  <link href="/mix/jquery-ui.min.css" rel="stylesheet">
  <link href="/mix/jquery-ui.theme.min.css" rel="stylesheet">
  <style>
    * {
      -webkit-box-sizing: initial;
      -moz-box-sizing: initial;
      box-sizing: initial;
    }

    td, th {
      vertical-align: middle !important;
    }

    .row_text {
      width: 200px;
      display: inline-block;
    }

    .small_text {
      width: 60px;
      display: inline;
    }

    .tip_text {
      color: #999;
      font-size: smaller;
    }

    #main_form th {
      width: 15%;
    }

    #top_setting_box .top_setting_item {
      margin-top: 10px;
    }

    #recharge_setting_box .recharge_setting_item {
      margin-top: 10px;
    }

    .prev_img {
      width: 150px;
      height: 100px;
      margin-top: 10px;
      margin-right: 10px;
    }
    .checkbox_item{
      display: flex;
      align-items: center;
    }
  </style>
</head>
<body>
<div class="layui-fluid" style="margin-top: 10px;">
  <div class="layui-row">
    <div class="layui-col-md12">
      <blockquote class="layui-elem-quote">添加子账户</blockquote>
      <form id="main_form" action="" method="post">
        {if $_GET['id']}
          <input type="hidden" name="id" value="{$_GET['id']}">
        {/if}
        <div class="layui-form-item layui-form">
          <label class="layui-form-label">登录账号</label>
          <div class="layui-input-block">
            <input type="text" name="username" class="layui-input" value="{$yg->username}">
            <div class="layui-form-mid layui-word-aux"></div>
          </div>
        </div>
        <div class="layui-form-item layui-form">
          <label class="layui-form-label">登录密码</label>
          <div class="layui-input-inline">
            <input type="password" name="password" class="layui-input" value="">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">权限</label>
          <div class="layui-input-block">
            {loop $indexList as $name=>$val}
            <label class="checkbox_item">
              <input type="checkbox" name="authority[]" value="{$name}" {if in_array($name,$userIndex)} checked {/if}>
              <span>{$name}</span>
            </label>
            {/loop}
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn layui-btn-lg btn-submit" type="button">保存</button>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
<script src="/mix/jquery.min.js"></script>
<script src="/mix/bootstrap.min.js"></script>
<script src="/layui/layui.js"></script>
<script src="/mix/jquery-ui.min.js"></script>
<script>
  layui.use(['laydate', 'layer', 'upload', 'form'], function () {
    var laydate = layui.laydate;
    var layer = layui.layer;
    var form = layui.form;
  });

  $('.btn-submit').on('click', function () {
    var formData = $('#main_form').serializeArray();
    console.log(formData);
    $.ajax({
      url: 'add.html',
      method: 'POST',
      data: formData,
      beforeSend: function () {
        layer.load();
      }, complete: function () {
        layer.closeAll('loading');
      }, success: function (resp) {
        console.log(resp);
        if (resp.status == 'success') {
          // location.reload(true);
          history.back();
        } else {
          alert(resp.msg);
        }
      }, error: function () {
        alert('网络故障，稍后重试');
      }
    });
  });
</script>
</body>
</html>